1 using System.Collections;
2 using
System.Collections.Generic;
3 using
UnityEngine;
4
5 public
class Background : MonoBehaviour {
6
7     
public float speed;
8
9     
private Vector2 offset = Vector2.zero;
10     
private Material mat;
11
12     
void Awake(){
13         
14     }
15
16     
// Use this for initialization
17     
void Start () {
18         InitializeBackground ();
19     }
20
21     
// Update is called once per frame
22     
void Update () {
23         
if (GameplayController.instance.startMoving) {
24             ScrollMovement ();
25         }
26     }
27
28     
void InitializeBackground(){
29         mat = GetComponent<Renderer> ().material;
30         offset = mat.GetTextureOffset (
"_MainTex");
31         
float height = Camera.main.orthographicSize * 2f;
32         
float width = height * Screen.width / Screen.height;
33
34         transform.localScale =
new Vector3 (width, height + 1, transform.position.z);
35     }
36
37     
void ScrollMovement(){
38         offset.y += speed * Time.deltaTime;
39         mat.SetTextureOffset (
"_MainTex", offset);
40     }
41 }


Use this for initialization

Update is called once per frame



Gõ tìm kiếm nhanh...